package com.srwl.mytx;

import android.content.Context;

import com.srwl.mytx.utils.PreferenceManager;

import java.util.HashMap;
import java.util.Map;

public class SettingModel {

    protected Context context = null;
    protected Map<Key, Object> valueCache = new HashMap<Key, Object>();

    public SettingModel(Context ctx) {
        context = ctx;
        PreferenceManager.init(context);
    }


    /**
     * save current username
     *
     * @param username
     */
    public void setCurrentUserName(String username) {
        PreferenceManager.getInstance().setUserName(username);
    }

    public String getCurrentUsernName() {
        return PreferenceManager.getInstance().getCurrentuserPhoneNumber();
    }


    public void setSettingMsgNotification(boolean paramBoolean) {
        PreferenceManager.getInstance().setSettingMsgNotification(paramBoolean);
        valueCache.put(Key.VibrateAndPlayToneOn, paramBoolean);
    }

    public boolean getSettingMsgNotification() {
        Object val = valueCache.get(Key.VibrateAndPlayToneOn);

        if (val == null) {
            val = PreferenceManager.getInstance().getSettingMsgNotification();
            valueCache.put(Key.VibrateAndPlayToneOn, val);
        }

        return (Boolean) (val != null ? val : true);
    }

    /**
     * 查看用户设置：好友解除 是否通知
     *
     * @return
     */
    public boolean getSettingDeleteMsgNotify() {
        Object val = valueCache.get(Key.DeleteNotify);
        if (val == null) {
            val = PreferenceManager.getInstance().getSettingMsgDeleteNotify();
            valueCache.put(Key.DeleteNotify, val);
        }
        return (boolean) val;
    }

    public void setSettingDeleteMsgNotify(boolean paramBoolean) {
        PreferenceManager.getInstance().setSettingMsgDeleteNotify(paramBoolean);
        valueCache.put(Key.DeleteNotify, paramBoolean);
    }


    public void setSettingMsgSound(boolean paramBoolean) {
        PreferenceManager.getInstance().setSettingMsgSound(paramBoolean);
        valueCache.put(Key.PlayToneOn, paramBoolean);
    }

    public boolean getSettingMsgSound() {
        Object val = valueCache.get(Key.PlayToneOn);

        if (val == null) {
            val = PreferenceManager.getInstance().getSettingMsgSound();
            valueCache.put(Key.PlayToneOn, val);
        }

        return (Boolean) (val != null ? val : true);
    }

    public void setSettingMsgVibrate(boolean paramBoolean) {
        PreferenceManager.getInstance().setSettingMsgVibrate(paramBoolean);
        valueCache.put(Key.VibrateOn, paramBoolean);
    }

    public boolean getSettingMsgVibrate() {
        Object val = valueCache.get(Key.VibrateOn);

        if (val == null) {
            val = PreferenceManager.getInstance().getSettingMsgVibrate();
            valueCache.put(Key.VibrateOn, val);
        }

        return (Boolean) (val != null ? val : true);
    }

    public void setSettingMsgSpeaker(boolean paramBoolean) {
        PreferenceManager.getInstance().setSettingMsgSpeaker(paramBoolean);
        valueCache.put(Key.SpakerOn, paramBoolean);
    }

    public boolean getSettingMsgSpeaker() {
        Object val = valueCache.get(Key.SpakerOn);

        if (val == null) {
            val = PreferenceManager.getInstance().getSettingMsgSpeaker();
            valueCache.put(Key.SpakerOn, val);
        }

        return (Boolean) (val != null ? val : true);
    }

    public void setSettingVoiceAutoPlay(boolean paramBoolean) {

        PreferenceManager.getInstance().setSettingVoiceAutoPlay(paramBoolean);
        valueCache.put(Key.VoiceAutoPlay, paramBoolean);
    }


    public boolean getSettingVoiceAutoPlay() {
        Object val = valueCache.get(Key.VoiceAutoPlay);
        if (val == null) {
            val = PreferenceManager.getInstance().getSettingVoiceAutoPlay();
            valueCache.put(Key.VoiceAutoPlay, val);
        }
        return (Boolean) val;
    }

    public void setSettingContactGroup(boolean groupModel) {
        PreferenceManager.getInstance().setSettingContactGroup(groupModel);
        valueCache.put(Key.GroupModel, groupModel);
    }

    public boolean getSettingContactGroup(){
        Object val = valueCache.get(Key.GroupModel);
        if (val == null) {
            val = PreferenceManager.getInstance().getSettingContactGroup();
            valueCache.put(Key.GroupModel, val);
        }
        return (Boolean) val;
    }


    public void setDeleteMessagesAsExitGroup(boolean value) {
        PreferenceManager.getInstance().setDeleteMessagesAsExitGroup(value);
    }

    public boolean isDeleteMessagesAsExitGroup() {
        return PreferenceManager.getInstance().isDeleteMessagesAsExitGroup();
    }

    public void setAutoAcceptGroupInvitation(boolean value) {
        PreferenceManager.getInstance().setAutoAcceptGroupInvitation(value);
    }

    public boolean isAutoAcceptGroupInvitation() {
        return PreferenceManager.getInstance().isAutoAcceptGroupInvitation();
    }

    public void setSettingSearchUserInfo(boolean isChecked) {
        PreferenceManager.getInstance().setSearchUserInfo(isChecked);
    }

    enum Key {
        VibrateAndPlayToneOn,
        VibrateOn,
        PlayToneOn,
        SpakerOn,
        DisabledGroups,
        DisabledIds,
        DeleteNotify,
        VoiceAutoPlay,
        GroupModel
    }

    public boolean isPushCall() {
        return PreferenceManager.getInstance().isPushCall();
    }


}
